import subprocess


def exe_shell(shell_str, path, encoding,shell_status):
    sub_obj = subprocess.Popen(shell_str, shell=True, cwd=path, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    stdout = sub_obj.stdout.read()
    stderr = sub_obj.stderr.read()
    returncode = sub_obj.returncode
    pid = sub_obj.pid
    if shell_status:
        sub_obj.kill()

    return {
        'returncode': returncode,
        'pid': pid,
        # 'stdout': stdout.decode(encoding=encoding).encode().decode('utf8') if stdout else '',
        # 'stderr': stderr.decode(encoding=encoding).encode().decode('utf8') if stderr else '',
        'stdout': stdout.decode(encoding=encoding) if stdout else '',
        'stderr': stderr,
    }


if __name__ == '__main__':
    # shell_str = 'dir'
    # path = r'D:\python3\jiangsqobj'
    # encoding = 'gbk'
    # shell_status = False
    # data = exe_shell(shell_str, path, encoding,shell_status)
    # print(data)
    a = b''
    print(a.decode(encoding='gbk').encode().decode('utf8'))
